package leetcode;

import java.util.Arrays;

/**
 * @program: datastructureandalogorithm
 * @description:
 * @author: hmx
 * @create: 2022-01-23 17:35
 **/
public class LeetCode5971 {

    public int minimumCost(int[] cost) {
        int n = cost.length;
        Arrays.sort(cost);
        int costs = 0;
        while (n >= 3) {
            costs += cost[n - 1] + cost[n - 2];
            n -= 3;
        }

        while (--n >= 0) {
            costs += cost[n];
        }

        return costs;
    }
}
